/**
 * 
 */
package com.bone.common.json;

import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * json字符串输出. 
 * @author yangbin
 *
 */
public abstract class JSONOutput {

	/**
	 * 向response输出json信息
	 * @param <T>
	 * @param res
	 * @param obj
	 */
	public static <T> void writeJSON(HttpServletResponse res, T obj) {
		writeJSON(res, obj, ENCODING);
	}
		
	public static<T> void writeJSON(HttpServletResponse res,T obj,String contentType){
		res.setContentType(contentType);
		res.setCharacterEncoding(ENCODING);
		try{
			res.getOutputStream().write(obj.toString().getBytes(ENCODING));
		}catch(Exception ex){
			logger.warn(ex);
		}
	}
	private static final Log logger=LogFactory.getLog(JSONOutput.class);
	private static final String ENCODING="UTF-8";
}
